﻿#include "button_flag.h"

bank3 char gButtonFlag[CHANNEL_NUM];
bank3 char  gButtonFlag_Times[CHANNEL_NUM];


void button_init()
{	
	char i;
	for(i = 0 ;i<CHANNEL_NUM;i++)
	{
		gButtonFlag[i] =  0;
		gButtonFlag_Times[i] = 0;
	}

}
char  Get_button_flag(char ch_num)
{
	return gButtonFlag[ch_num];
}

/**
 * @brief 按键判断
 * 
 */
void Button_Flag_Judge()  //touch
{
	char i;
 	for(i= 0;i<CHANNEL_NUM;i++)
	{
		if(gButtonFlag[i] == 0)
		{
		
			if(Get_Forceflag(i) == POS_TOUCH)
			{
				if(Get_ForceData(i) > gKeyDownLevel[i])
				{
					gButtonFlag_Times[i]++;
				}
			}
			else
			{
				gButtonFlag_Times[i] = 0;
			}
			//消抖
			if(gButtonFlag_Times[i]>5)
			{
				gButtonFlag[i] = 1;
			}
		}
		else
		{
			if(Get_ForceData(i)<(gKeyDownLevel[i]>>1))//小于0.5的阈值
			{
				gButtonFlag[i] = 0;
				gButtonFlag_Times[i] = 0;
			}
		}
	}
	
	

}
/**
 * @brief 业务代码实现
 * 
 */
void Hal_Gpio_Event()
{
	/*根据具体业务实现*/
	
	
}
/**
 * @brief 确定最终button
 * 
 */
void button_flag_process()
{
	//button_flag判断
	Button_Flag_Judge();
	
}